package com.androidx.p013lv.mine.fragment;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStoreOwner;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.DeviceIDUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.mine.C1207R;
import com.androidx.p013lv.mine.adapter.VipCenterTicketAdapter;
import com.androidx.p013lv.mine.bean.PayBean;
import com.androidx.p013lv.mine.bean.RechargeBean;
import com.androidx.p013lv.mine.bean.VipCenterBean;
import com.androidx.p013lv.mine.databinding.FragmentTicketsBinding;
import com.androidx.p013lv.mine.model.VipCenterModel;
import com.google.gson.Gson;
import com.yalantis.ucrop.util.ScreenUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/* renamed from: com.androidx.lv.mine.fragment.TicketsFragment */
public class TicketsFragment extends LazyFragment<FragmentTicketsBinding> implements ItemClickListener {
    private VipCenterTicketAdapter adapter;
    private Animation animationIn;
    private Animation animationOut;
    private RechargeBean bean;
    private OnClick click;
    private List<ImageView> itemImg;
    private List<LinearLayout> itemPays;
    private VipCenterModel model;
    private PopupWindow payView;
    private LinearLayout pop_pay_view;
    int source;
    private List<VipCenterBean.TicketsBean> ticketsList;

    public static TicketsFragment newInstance(int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("data", i);
        TicketsFragment ticketsFragment = new TicketsFragment();
        ticketsFragment.setArguments(bundle);
        return ticketsFragment;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        this.source = bundle.getInt("data");
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return C1207R.C1212layout.fragment_tickets;
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        RechargeBean rechargeBean = new RechargeBean();
        this.bean = rechargeBean;
        rechargeBean.setSource(this.source);
        this.click = new OnClick();
        ((FragmentTicketsBinding) this.binding).setClick(this.click);
        ((FragmentTicketsBinding) this.binding).setIsEmpty(0);
        initPayView();
        initPrompt();
        this.model = (VipCenterModel) new ViewModelProvider(this).get(VipCenterModel.class);
        this.ticketsList = new ArrayList();
        VipCenterTicketAdapter vipCenterTicketAdapter = new VipCenterTicketAdapter();
        this.adapter = vipCenterTicketAdapter;
        vipCenterTicketAdapter.setItemListener(this);
        ((FragmentTicketsBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getContext(), 0, false));
        ((FragmentTicketsBinding) this.binding).recycler.setAdapter(this.adapter);
        this.bean.setDeviceId(DeviceIDUtils.getUniqueId((Context) Objects.requireNonNull(getContext())));
        ((VipCenterModel) new ViewModelProvider((ViewModelStoreOwner) Objects.requireNonNull(getActivity())).get(VipCenterModel.class)).dataVipCenter().observe(this, new Observer<BaseRes<VipCenterBean>>() {
            /* class com.androidx.p013lv.mine.fragment.TicketsFragment.C13301 */

            public void onChanged(BaseRes<VipCenterBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    TicketsFragment.this.ticketsList = baseRes.getData().getTicketsList();
                    TicketsFragment.this.adapter.setData(TicketsFragment.this.ticketsList);
                    if (TicketsFragment.this.ticketsList == null || TicketsFragment.this.ticketsList.size() <= 0) {
                        ((FragmentTicketsBinding) TicketsFragment.this.binding).setIsEmpty(0);
                        TicketsFragment.this.bean.setRechType(-1);
                        TicketsFragment.this.bean.setMoney(0);
                        return;
                    }
                    ((FragmentTicketsBinding) TicketsFragment.this.binding).setIsEmpty(1);
                    TicketsFragment.this.clickTicketCard(0);
                    return;
                }
                ((FragmentTicketsBinding) TicketsFragment.this.binding).setIsEmpty(0);
                ToastUtils.getInstance().showSigh(baseRes.getMsg());
            }
        });
        this.model.dataPay().observe(this, new Observer<BaseRes<PayBean>>() {
            /* class com.androidx.p013lv.mine.fragment.TicketsFragment.C13312 */

            public void onChanged(BaseRes<PayBean> baseRes) {
                if (baseRes.getCode() == 200) {
                    PayBean data = baseRes.getData();
                    ARouter.getInstance().build(Constance.RECHARGE_HINT_ACTIVITY).navigation();
                    try {
                        Intent intent = new Intent();
                        intent.setAction("android.intent.action.VIEW");
                        intent.setData(Uri.parse(data.getUrl()));
                        TicketsFragment.this.startActivity(intent);
                    } catch (Exception e) {
                        e.printStackTrace();
                        ToastUtils.getInstance().showWeak("支付失敗");
                    }
                } else {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    private void initPayView() {
        this.itemPays = new ArrayList();
        this.itemImg = new ArrayList();
        this.animationIn = AnimationUtils.loadAnimation(getContext(), C1207R.anim.pop_window_in);
        this.animationOut = AnimationUtils.loadAnimation(getContext(), C1207R.anim.pop_window_out);
        View inflate = View.inflate(getContext(), C1207R.C1212layout.popup_ticket_pay, null);
        this.pop_pay_view = (LinearLayout) inflate.findViewById(C1207R.C1210id.pop_pay_view);
        this.animationOut.setAnimationListener(new Animation.AnimationListener() {
            /* class com.androidx.p013lv.mine.fragment.TicketsFragment.animationAnimation$AnimationListenerC13323 */

            public void onAnimationRepeat(Animation animation) {
            }

            public void onAnimationStart(Animation animation) {
            }

            public void onAnimationEnd(Animation animation) {
                TicketsFragment.this.payView.dismiss();
            }
        });
        inflate.findViewById(C1207R.C1210id.btn_v_out).setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.fragment.TicketsFragment.View$OnClickListenerC13334 */

            public void onClick(View view) {
                TicketsFragment.this.pop_pay_view.startAnimation(TicketsFragment.this.animationOut);
            }
        });
        LinearLayout linearLayout = (LinearLayout) inflate.findViewById(C1207R.C1210id.btn_wechat);
        linearLayout.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.fragment.TicketsFragment.View$OnClickListenerC13345 */

            public void onClick(View view) {
                TicketsFragment.this.bean.setRechType(2);
                TicketsFragment.this.click.selectPay(0);
                TicketsFragment.this.pop_pay_view.startAnimation(TicketsFragment.this.animationOut);
                TicketsFragment.this.model.rechargePay(new Gson().toJson(TicketsFragment.this.bean), TicketsFragment.this.getContext());
            }
        });
        this.itemPays.add(linearLayout);
        LinearLayout linearLayout2 = (LinearLayout) inflate.findViewById(C1207R.C1210id.btn_alipay);
        linearLayout2.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.fragment.TicketsFragment.View$OnClickListenerC13356 */

            public void onClick(View view) {
                TicketsFragment.this.bean.setRechType(1);
                TicketsFragment.this.click.selectPay(1);
                TicketsFragment.this.pop_pay_view.startAnimation(TicketsFragment.this.animationOut);
                TicketsFragment.this.model.rechargePay(new Gson().toJson(TicketsFragment.this.bean), TicketsFragment.this.getContext());
            }
        });
        this.itemPays.add(linearLayout2);
        LinearLayout linearLayout3 = (LinearLayout) inflate.findViewById(C1207R.C1210id.btn_ysf);
        linearLayout3.setOnClickListener(new View.OnClickListener() {
            /* class com.androidx.p013lv.mine.fragment.TicketsFragment.View$OnClickListenerC13367 */

            public void onClick(View view) {
                TicketsFragment.this.bean.setRechType(3);
                TicketsFragment.this.click.selectPay(2);
                TicketsFragment.this.pop_pay_view.startAnimation(TicketsFragment.this.animationOut);
                TicketsFragment.this.model.rechargePay(new Gson().toJson(TicketsFragment.this.bean), TicketsFragment.this.getContext());
            }
        });
        this.itemPays.add(linearLayout3);
        this.itemImg.add((ImageView) inflate.findViewById(C1207R.C1210id.img_we_chat));
        this.itemImg.add((ImageView) inflate.findViewById(C1207R.C1210id.img_alipay));
        this.itemImg.add((ImageView) inflate.findViewById(C1207R.C1210id.f258a));
        PopupWindow popupWindow = new PopupWindow(inflate, -1, -1);
        this.payView = popupWindow;
        popupWindow.setOutsideTouchable(true);
        this.payView.setBackgroundDrawable(new ColorDrawable());
        this.payView.setClippingEnabled(false);
    }

    private void initPrompt() {
        SpannableString spannableString = new SpannableString("免費解鎖約吧全部高端嫩模聯系方式");
        spannableString.setSpan(new StyleSpan(1), 0, 4, 33);
        spannableString.setSpan(new StyleSpan(1), 8, 12, 33);
        ((FragmentTicketsBinding) this.binding).tvOne.setText(spannableString);
        SpannableString spannableString2 = new SpannableString("高端嫩模一对一匹配服務");
        spannableString2.setSpan(new StyleSpan(1), 4, 7, 33);
        ((FragmentTicketsBinding) this.binding).tvTwo.setText(spannableString2);
        SpannableString spannableString3 = new SpannableString("溫馨提示：如您在選定嫩模後，無故失約1次，將會取消您的約炮卡權益哦");
        spannableString3.setSpan(new StyleSpan(1), 0, 4, 33);
        spannableString3.setSpan(new ForegroundColorSpan(Color.parseColor("#DC1C1E")), 16, 20, 33);
        spannableString3.setSpan(new StyleSpan(1), 16, 20, 33);
        spannableString3.setSpan(new ForegroundColorSpan(Color.parseColor("#DC1C1E")), 23, 25, 33);
        spannableString3.setSpan(new StyleSpan(1), 23, 25, 33);
        spannableString3.setSpan(new ForegroundColorSpan(Color.parseColor("#DC1C1E")), 27, 32, 33);
        spannableString3.setSpan(new StyleSpan(1), 27, 32, 33);
        ((FragmentTicketsBinding) this.binding).tvPrompt.setText(spannableString3);
        ViewGroup.LayoutParams layoutParams = ((FragmentTicketsBinding) this.binding).ivTicketStayTuned.getLayoutParams();
        double screenWidth = (double) ScreenUtils.getScreenWidth((Context) Objects.requireNonNull(getContext()));
        Double.isNaN(screenWidth);
        layoutParams.width = (int) (screenWidth / 2.8d);
        double d = (double) layoutParams.width;
        Double.isNaN(d);
        layoutParams.height = (int) (d / 1.666667d);
        ((FragmentTicketsBinding) this.binding).ivTicketStayTuned.setLayoutParams(layoutParams);
    }

    private void setVipType(List<VipCenterBean.TypesBean> list) {
        for (LinearLayout linearLayout : this.itemPays) {
            linearLayout.setVisibility(8);
        }
        if (list != null && list.size() > 0) {
            for (VipCenterBean.TypesBean typesBean : list) {
                String payMent = typesBean.getPayMent();
                char c = 65535;
                switch (payMent.hashCode()) {
                    case 1507424:
                        if (payMent.equals("1001")) {
                            c = 0;
                            break;
                        }
                        break;
                    case 1507425:
                        if (payMent.equals("1002")) {
                            c = 1;
                            break;
                        }
                        break;
                    case 1507426:
                        if (payMent.equals("1003")) {
                            c = 2;
                            break;
                        }
                        break;
                }
                if (c == 0) {
                    this.itemPays.get(1).setVisibility(0);
                } else if (c == 1) {
                    this.itemPays.get(0).setVisibility(0);
                } else if (c == 2) {
                    this.itemPays.get(2).setVisibility(0);
                }
            }
        }
    }

    private void addTicketsDetails(List<String> list) {
        ((FragmentTicketsBinding) this.binding).llTicketsAdd.removeAllViews();
        int i = 0;
        while (i < list.size()) {
            LinearLayout linearLayout = new LinearLayout(getContext());
            linearLayout.setOrientation(0);
            linearLayout.setGravity(16);
            TextView textView = new TextView(getContext());
            StringBuilder sb = new StringBuilder();
            int i2 = i + 1;
            sb.append(i2);
            sb.append("");
            textView.setText(sb.toString());
            textView.setTextSize(8.0f);
            textView.setTextColor(getResources().getColor(C1207R.C1208color.white));
            textView.setBackgroundResource(C1207R.C1209drawable.mine_bg_tickets_number);
            textView.setGravity(17);
            linearLayout.addView(textView);
            TextView textView2 = new TextView(getContext());
            textView2.setText(list.get(i));
            textView2.setTextSize(12.0f);
            textView2.setTextColor(getResources().getColor(C1207R.C1208color.white));
            textView2.setGravity(16);
            linearLayout.addView(textView2);
            ((FragmentTicketsBinding) this.binding).llTicketsAdd.addView(linearLayout);
            i = i2;
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void clickTicketCard(int i) {
        for (int i2 = 0; i2 < this.ticketsList.size(); i2++) {
            this.ticketsList.get(i2).setSelected(false);
        }
        VipCenterBean.TicketsBean ticketsBean = this.ticketsList.get(i);
        ticketsBean.setSelected(true);
        setVipType(ticketsBean.getTypes());
        this.bean.setMoney(ticketsBean.getPrice());
        this.bean.setTid(ticketsBean.getTid());
        this.bean.setPurType(13);
        this.adapter.setData(this.ticketsList);
        ((FragmentTicketsBinding) this.binding).setBean(this.bean);
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        clickTicketCard(i);
    }

    /* renamed from: com.androidx.lv.mine.fragment.TicketsFragment$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void commitPay() {
            if (TicketsFragment.this.bean.getMoney() == 0 || TicketsFragment.this.bean.getPurType() == 0 || TicketsFragment.this.bean.getTid() == 0) {
                ToastUtils.getInstance().showSigh("請選擇門票");
                return;
            }
            for (ImageView imageView : TicketsFragment.this.itemImg) {
                imageView.setImageResource(C1207R.C1209drawable.mine_ic_btn_un_selected);
            }
            TicketsFragment.this.pop_pay_view.startAnimation(TicketsFragment.this.animationIn);
            TicketsFragment.this.payView.showAtLocation(((FragmentActivity) Objects.requireNonNull(TicketsFragment.this.getActivity())).getWindow().getDecorView(), 17, 0, 0);
        }

        public void selectPay(int i) {
            for (ImageView imageView : TicketsFragment.this.itemImg) {
                imageView.setImageResource(C1207R.C1209drawable.mine_ic_btn_un_selected);
            }
            ((ImageView) TicketsFragment.this.itemImg.get(i)).setImageResource(C1207R.C1209drawable.mine_ic_btn_selected);
        }
    }

    @Override // androidx.fragment.app.Fragment, com.androidx.p013lv.base.p015ui.LazyFragment
    public void onDestroyView() {
        Animation animation = this.animationIn;
        if (animation != null) {
            animation.cancel();
        }
        Animation animation2 = this.animationOut;
        if (animation2 != null) {
            animation2.cancel();
        }
        VipCenterModel vipCenterModel = this.model;
        if (vipCenterModel != null) {
            vipCenterModel.cancelHttp();
        }
        super.onDestroyView();
    }
}
